home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Text⁄Files
/
Voyeur 1.1.1
/
Voyeur ƒ
/
MSG Shell ƒ
/
msg main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-27
|
8KB
|
342 lines
/**********************************************************************\
File: msg main.c
Purpose: This module handles the event loop and event dispatching.
Voyeur -- a no-frills file viewer
Copyright ©1993-4, Mark Pilgrim
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program in a file named "GNU General Public License".
If not, write to the Free Software Foundation, 675 Mass Ave,
Cambridge, MA 02139, USA.
\**********************************************************************/
#include "msg main.h"
#include "msg integrity.h"
#include "msg graphics.h"
#include "msg about.h"
#include "msg help.h"
#include "msg menus.h"
#include "msg prefs.h"
#include "msg environment.h"
#include "Mercutio API.h"
#include "v.h"
#include "v progress.h"
#include "v window maintenance.h"
#include "v error.h"
#include "program globals.h"
#include "AppleEvents.h"
#include "EPPC.h"
void main(void)
{
MaxApplZone();
InitGraf(&thePort);
InitFonts();
FlushEvents(everyEvent, 0);
InitWindows();
InitMenus();
TEInit();
InitDialogs(0L);
InitCursor();
GetDateTime(&randSeed);
CheckEnvironment();
DoIntegrityCheck();
InitMSGGraphics();
InitHelp();
PrefsError(PreferencesInit());
InitEnvironment();
InitProgram();
EventLoop();
ShutDownEnvironment();
ExitToShell();
}
void EventLoop(void)
{
EventRecord theEvent;
int i;
while (!gDone)
{
SetCursor(&arrow);
HiliteMenu(0);
if (FrontWindow()!=0L)
{
for (i=0; i<NUM_WINDOWS; i++)
{
if (FrontWindow()==gTheWindow[i])
{
SetPort(gTheWindow[i]);
i=NUM_WINDOWS;
}
}
if (IsProgramWindow(FrontWindow()))
gWhichFile=GetProgramWindowIndex(FrontWindow());
}
WaitNextEvent(everyEvent, &theEvent, gIsInBackground ? 100 :
(((gTheWindow[kAboutMSG]!=0L) && (FrontWindow()==gTheWindow[kAboutMSG])) ?
0 : (gNeedOpenDialog ? 0 : 30)), 0L);
DispatchEvents(theEvent);
if ((!gIsInBackground) && (gTheWindow[kAboutMSG]!=0L) &&
(FrontWindow()==gTheWindow[kAboutMSG]))
DoTheMSGThing();
}
}
void DispatchEvents(EventRecord theEvent)
{
int i;
OSErr isHuman;
Point thisPoint;
int index;
char thisChar;
unsigned long dummy;
WindowPtr theWindow;
index=-1;
if ((theWindow=FrontWindow())!=0L)
{
for (i=0; (i<NUM_WINDOWS) && (index==-1); i++)
if (theWindow==gTheWindow[i])
index=i;
}
switch (theEvent.what)
{
case nullEvent:
if ((gNeedOpenDialog) && (!gIsInBackground))
{
gNeedCounter++;
if (gNeedCounter==2)
{
HandleError(NewEditWindow());
gNeedOpenDialog=FALSE;
}
}
break;
case mouseDown:
HandleMouseDown(theEvent);
break;
case keyDown:
case autoKey:
thisChar=(char)(theEvent.message & charCodeMask);
if (theEvent.modifiers & cmdKey)
{
AdjustMenus();
dummy=PowerMenuKey(theEvent.message, theEvent.modifiers, gFileMenu);
if (dummy==0L)
dummy=PowerMenuKey(theEvent.message, theEvent.modifiers, gOptionsMenu);
if (dummy==0L)
dummy=MenuKey(thisChar);
HandleMenu(dummy);
}
else
switch (index)
{
case kAbout:
CloseTheWindow(index);
break;
case kAboutMSG:
UpdateTheWindow(index);
Delay(30, &dummy);
CloseTheWindow(index);
break;
case kHelp:
HelpKeyEvent(thisChar);
break;
default:
if (IsProgramWindow(theWindow))
ProgramKeyEvent(thisChar);
break;
}
break;
case diskEvt:
if (HiWord(theEvent.message)!=noErr)
{
DILoad();
SetPt(&thisPoint, 120, 120);
isHuman=DIBadMount(thisPoint, theEvent.message);
DIUnload();
}
break;
case updateEvt:
theWindow=(WindowPtr)theEvent.message;
BeginUpdate(theWindow);
if (IsProgramWindow(theWindow))
UpdateProgramWindow(GetProgramWindowIndex(theWindow), FALSE);
else
{
for (i=0; i<NUM_WINDOWS; i++)
if ((WindowPtr)theEvent.message == gTheWindow[i])
UpdateTheWindow(i);
if ((theWindow!=0L) && (theWindow==gProgressDlog))
UpdateDialog(theWindow, theWindow->visRgn);
}
EndUpdate(theWindow);
break;
case activateEvt:
if (((WindowPtr)theEvent.message==gTheWindow[kAboutMSG]) &&
((theEvent.modifiers&activeFlag)==0))
UpdateTheWindow(kAboutMSG);
break;
case osEvt:
if (((theEvent.message>>24)&0x0FF)==suspendResumeMessage)
{
gIsInBackground=((theEvent.message&resumeFlag)==0);
if ((gIsInBackground) && ((gTheWindow[kAboutMSG]!=0L) &&
(FrontWindow()==gTheWindow[kAboutMSG])))
UpdateTheWindow(kAboutMSG);
if ((!gIsInBackground) && (gPendingResultCode!=allsWell))
{
if (gHasNotificationManager)
NMRemove(&gMyNotification);
HandleError(gPendingResultCode);
gPendingResultCode=allsWell;
}
}
break;
case kHighLevelEvent:
if (gHasAppleEvents)
AEProcessAppleEvent(&theEvent);
break;
}
}
void HandleMouseDown(EventRecord theEvent)
{
WindowPtr theWindow;
int windowCode;
long windSize;
GrafPtr oldPort;
int i;
Rect sizeRect;
Boolean gotone;
int index;
unsigned long dummy;
windowCode=FindWindow(theEvent.where, &theWindow);
index=-1;
for (i=0; (i<NUM_WINDOWS) && (index==-1); i++)
if (theWindow==gTheWindow[i])
index=i;
switch (windowCode)
{
case inMenuBar:
AdjustMenus();
HandleMenu(MenuSelect(theEvent.where));
break;
case inContent:
if (FrontWindow() != theWindow)
{
if (FrontWindow()==gProgressDlog)
SysBeep(7);
else
{
if (FrontWindow()==gTheWindow[kAboutMSG])
UpdateTheWindow(kAboutMSG);
if (IsProgramWindow(theWindow))
SelectProgramWindow(theWindow);
else
SelectWindow(theWindow);
}
}
else
switch (index)
{
case kAbout:
CloseTheWindow(index);
break;
case kAboutMSG:
UpdateTheWindow(index);
Delay(30, &dummy);
CloseTheWindow(index);
break;
case kHelp:
HelpEvent();
break;
default:
if (IsProgramWindow(theWindow))
ProgramEvent();
break;
}
break;
case inSysWindow:
SystemClick(&theEvent, theWindow);
break;
case inDrag:
DragWindow(theWindow, theEvent.where, &gDragRect);
if (index>=0)
gWindowBounds[index] = (*(((WindowPeek)gTheWindow[index])->contRgn))->rgnBBox;
break;
case inGoAway:
if (TrackGoAway(theWindow, theEvent.where))
DoTheCloseThing(theWindow);
break;
case inGrow:
sizeRect = screenBits.bounds;
OffsetRect(&sizeRect, sizeRect.left, sizeRect.top);
windSize = GrowWindow(theWindow, theEvent.where, &sizeRect);
if(windSize != 0)
{
GetPort(&oldPort);
SetPort(theWindow);
EraseRect(&theWindow->portRect);
SizeWindow(theWindow, LoWord(windSize), HiWord(windSize), TRUE);
InvalRect(&theWindow->portRect);
SetPort(oldPort);
}
if (index>=0)
gWindowBounds[index] = (*(((WindowPeek)gTheWindow[index])->contRgn))->rgnBBox;
break;
case inZoomIn:
case inZoomOut:
if(TrackBox(theWindow, theEvent.where, windowCode))
{
GetPort(&oldPort);
SetPort(theWindow);
ZoomWindow(theWindow, windowCode, FALSE);
InvalRect(&theWindow->portRect);
SetPort(oldPort);
}
if (index>=0)
gWindowBounds[index] = (*(((WindowPeek)gTheWindow[index])->contRgn))->rgnBBox;
break;
}
}
void ShutDownEnvironment(void)
{
ShutDownProgram();
ShutDownMSGGraphics();
ShutDownHelp();
}